package com.xyhuo.leetcode.y2025;

import com.xyhuo.leetcode.common.ListNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class IsPalindrome {

    public boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        ListNode node = head;
        while (node != null) {
            list.add(node.val);
            node = node.next;
        }
        int len = list.size();
        for (int i = 0; i < len / 2; i++) {
            if (!Objects.equals(list.get(i), list.get(len - 1 - i))) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        IsPalindrome i = new IsPalindrome();
        ListNode l1 = new ListNode(1);
        ListNode l2 = new ListNode(2);
        ListNode l3 = new ListNode(2);
        ListNode l4 = new ListNode(1);
        l1.next = l2;
        l2.next = l3;
        l3.next = l4;
        i.isPalindrome(l1);
    }
}
